﻿
@{
    ViewData["Title"] = "Edit";
    Layout = "~/Views/Shared/_Layout.cshtml";
}


<div id="divForm" style="margin:2px;padding:2px;">
    <el-form ref="form" :model="form" label-width="80px">
        <el-row :gutter="24">
            <el-col :span="6">
                <el-form-item label="用户名称" required>
                    <el-input v-model="form.userName"></el-input>
                </el-form-item>
            </el-col>
        </el-row>
        <el-row :gutter="24">
            <el-col :span="6">
                <el-form-item label="真实名称" required>
                    <el-input v-model="form.realName"></el-input>
                </el-form-item>
            </el-col>
        </el-row>
        <el-row :gutter="24">
            <el-col :span="6">
                <el-form-item label="密码" required>
                    <el-input v-model="form.password" type="password"></el-input>
                </el-form-item>
            </el-col>
        </el-row>
        <el-row :gutter="24">
            <el-col :span="6">
                <el-form-item label="确认密码" required>
                    <el-input v-model="form.comfirmpassword" type="password">  </el-input>
                </el-form-item>
            </el-col>
        </el-row>
        <el-row :gutter="24">
            <el-col :span="6">
                <el-form-item label="状态">
                    <el-radio-group v-model="form.enabled">
                        <el-radio :label='true'>启用</el-radio>
                        <el-radio :label='false'>禁用</el-radio>
                    </el-radio-group>
                </el-form-item>
            </el-col>
        </el-row>
        <el-form-item>
            <el-button type="primary" @@click="SaveUser()" size="mini" v-show="pageButtons.includes('saveuser')">保存</el-button>
            <el-button @@click="Back()" size="mini">返回</el-button>
        </el-form-item>
    </el-form>
</div>
<script>

    var vueProject = new Vue({
        el: '#divForm',
        data() {
            return {
                pageButtons: [],
                form: {
                    id: parseInt( getQueryString("id") || 0),
                    userName: "",
                    realName: "",
                    enabled: true,
                    orderIndex: 0,
                    password: "",
                    comfirmpassword:"",
                    remark: ""
                }
            }
        },
        created() {
            var _this = this;
            _this.GetUser();
            _this.$getMenuButtons();
        },
        methods: {
            GetUser() {
                var _this = this;
                _this.$get("@Url.Action("GetUser", "user")?userId=" + _this.form.id).then((res) => {
                    _this.form = res;
                });
            },
            SaveUser() {
                var _this = this;
                if (_this.$isNullOrEmpty(_this.form.userName)) {
                    _this.$failed("请输入用户名称");
                    return;
                }
                if (_this.$isNullOrEmpty(_this.form.realName)) {
                    _this.$failed("请输入真实名称");
                    return;
                }

                if (_this.form.id == 0) {
                    if (_this.$isNullOrEmpty(_this.form.password)) {
                        _this.$failed("请输入密码");
                        return;
                    }
                    if (_this.$isNullOrEmpty(_this.form.comfirmpassword)) {
                        _this.$failed("请输入确认密码");
                        return;
                    }
                }
                if (_this.form.password != _this.form.comfirmpassword) {
                    _this.$failed("密码和确认密码必须一致");
                    return;
                }

                _this.form.orderIndex = parseInt(_this.form.orderIndex);
                _this.$post("@Url.Action("SaveUser", "user")", _this.form).then((res) => {
                    if (res.success == true) {
                        _this.$success(res.message, function () {
                            _this.$back(true);
                        });
                    } else {
                        _this.$failed(res.message);
                    }

                });
            },
            Back() {
                this.$back();
            }
        }
    });
</script>